var Manager = function() {
	this.user;
	this.element;
	this.laytpl;
	this.table;
	this.layer;
	this.tabMenu;
}
Manager.prototype = {
	init : function(user, element, laytpl, layer, tabMenu) {
		this.user = user;
		this.element = element;
		this.laytpl = laytpl;
		this.layer = layer;
		this.tabMenu = tabMenu;
		// location.hash = 'manager=index';
		this.queryProduct();
		this.initClickMenu();

		// Hash地址的定位
		var layid = location.hash.replace(/^#manager=/, '');
		$("#leftmenu a[htmlurl='" + layid + "']").click();

		// 监听Tab切换，以改变地址hash值
		this.element.on('tab(manager)', function() {
			location.hash = 'manager=' + this.getAttribute('lay-id');
		});
		this.tabMenu('manager', {
			tabMenu : true
		});

	},
	queryProduct : function() {
		var that = this;
		var loadindex = that.layer.load(0);
		$.ajax({
			url : "/product/queryAll",
			data : that.user,
			dataType : "json",
			type : "post",
			async : false,
			success : function(response) {
				var data = response.data;
				var getTpl = product.innerHTML
				that.laytpl(getTpl).render(data, function(html) {
					$("#leftmenu").html(html);
				});
				that.element.render("nav");
				that.layer.close(loadindex);
			}
		});
	},
	initClickMenu : function() {
		var that = this;
		this.element.on('nav(leftmenu)', function(elem) {
			var title = elem.text();
			var url = elem.attr("htmlurl");
			if (!url) {
				return;
			}
			if (url.substring(0, 1) != '/') {
				url = "/" + url;
			}
			location.hash = 'manager=' + url;
			that.addTab(title, url);
		});
	},
	addTab : function(title, url) {
		var that = this;
		var tabs = $("#manager li[lay-id='" + url + "']");
		if (tabs.length == 0) {
			var html = getHtml(url);
			this.element.tabAdd('manager', {
				title : title,
				content : html,
				id : url
			});
		}
		this.tabMenu('manager', {
			tabMenu : true
		});
		this.element.tabChange("manager", url);
	}
}
